#include "Blocks/FurnaceBlock.h"
#include "Components/ComponentMiner.h"
#include "Components/ComponentCreature.h"
#include "Components/ComponentCreatureModel.h"

namespace PocketSurvival
{
	bool FurnaceBlock::isFaceTransparent(int32_t face, int32_t value)
	{
		return false;
	}

    BlockPlacementData FurnaceBlock::getPlacementValue(ComponentMiner *componentMiner, int32_t value, const TerrainRaycastResult &raycastResult)
    {
		Vector3 forward = componentMiner->componentCreature->componentCreatureModel->getEyeRotation().toMatrix().getForward();
		float numBuff[4] = {
			Vector3::Dot(forward, FastVector3::UnitZ),
			Vector3::Dot(forward, FastVector3::UnitX),
			Vector3::Dot(forward, FastVector3::DecUnitZ),
			Vector3::Dot(forward, FastVector3::DecUnitX)
		};
		uint32_t targetIndex = MathUtils::MaxIndex<float>(numBuff, 4);
		int32_t data = 0;
		switch (targetIndex)
		{
		case 0:
			data = 2;
			break;
		case 1:
			data = 3;
			break;
		case 2:
			data = 0;
			break;
		case 3:
			data = 1;
			break;
		}
		BlockPlacementData result;
		result.value = Terrain::ReplaceData(Terrain::ReplaceContents(0, Index()), data);
		result.cellFace = raycastResult.cellFace;
		return result;
    }

    int32_t FurnaceBlock::getIndex()
    {
        return Index();
    }
	
    const std::string &FurnaceBlock::getBlockName()
    {
        static std::string blockName = "FurnaceBlock";
        return blockName;
    }

} // namespace PocketSurvival
